package com.jt.resource.config;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
//@Configuration
public class CorsFilterConfig {
    @Bean
    public FilterRegistrationBean<CorsFilter> fileterRegistrationBean(){
    UrlBasedCorsConfigurationSource configSource = new UrlBasedCorsConfigurationSource();
    CorsConfiguration config = new CorsConfiguration();
    config.addAllowedHeader("*");
    config.addAllowedMethod("*");
    config.addAllowedOrigin("*");
    config.setAllowCredentials(true);
    configSource.registerCorsConfiguration("/**",config);
    FilterRegistrationBean fBean=new FilterRegistrationBean(
            new CorsFilter(configSource));
    fBean.setOrder(Integer.MIN_VALUE);
    return fBean;
    }
}
